//
//  FanliPageViewController.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/9/6.
//

#import "FanliPageViewController.h"
#import "FanliPageListViewController.h"

@interface FanliPageViewController ()<WMPageControllerDelegate,WMPageControllerDataSource>

@property (nonatomic, strong) NSMutableArray *typeIds;
@property (nonatomic, strong) NSMutableArray *typeNames;

@end

@implementation FanliPageViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.centerTitle.text = @"返利申请";
    self.rightBtn.frame = CGRectMake(SL_WINDOW_WIDTH - 100, UIDevice.vg_statusBarHeight, 100, UIDevice.vg_navigationBarHeight);
    [self.rightBtn setTitle:@"返利指南" forState:UIControlStateNormal];
}

-(instancetype)initWithClassifys:(NSArray * )spaceClassifys
{
    self = [super init];
    if (self) {
        self.typeIds = [NSMutableArray array];
        self.typeNames = [NSMutableArray array];
        for (NSDictionary *classify in spaceClassifys) {
            [self.typeIds addObject:classify[@"typeId"]];
            [self.typeNames addObject:classify[@"typeName"]];
        }
        [self configMenu];
    }
    return self;
}

-(void)configMenu
{    
    self.titles = self.typeNames;
    self.menuViewStyle = WMMenuViewStyleLine;
    self.titleColorSelected =  kThemeTitleColor;
    self.titleSizeNormal  = 16;
    self.titleColorNormal = kColor888888;
    self.progressColor = kThemeTitleColor;
}

/// 标题
- (void)setTitles:(NSArray<NSString *> *)titles {
    [super setTitles:titles];
    NSMutableArray *tempItemsWidths = [NSMutableArray arrayWithCapacity:0];
    NSMutableArray *progressViewWidths = [NSMutableArray arrayWithCapacity:0];
    
    for (NSString *str in self.titles) {
        CGFloat width = ceil([str boundingRectWithSize:CGSizeMake(MAXFLOAT, self.titleSizeNormal) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:self.titleSizeNormal]} context:nil].size.width);
        [progressViewWidths addObject:@(width)];
        width += 25;
        [tempItemsWidths addObject:@(width)];
    }
    self.progressViewWidths = progressViewWidths;
    self.itemsWidths = tempItemsWidths;
}

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titles.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.titles[index];
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    FanliPageListViewController *vc = [[FanliPageListViewController alloc] initWithType:self.typeIds[index]];
    return vc;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, UIDevice.vg_navigationFullHeight, SL_WINDOW_WIDTH, 44);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    CGFloat originY = CGRectGetMaxY([self pageController:pageController preferredFrameForMenuView:self.menuView]);
    return CGRectMake(0, originY, SL_WINDOW_WIDTH, SL_WINDOW_HEIGHT - originY);
}

- (void)rightBtnClick
{
    [[AppLogic sharedInstance] pushToWebViewVC:@"返利指南" url:@"https://www.7pa.com/yhhnqply.html"];
}

@end
